const Koa = require("koa");
const Router = require("koa-router");
const views = require("koa-views");
const static = require("koa-static");
let app = new Koa();
let router = new Router();

const server = require('http').createServer(app.callback());
const io = require('socket.io')(server);
// 监听websocket连接
io.on("connection",socket=>{
      console.log("有连接过来");
      socket.on("sendpos",res=>{
         console.log(res);
         socket.broadcast.emit("sendClientPos",res)  // 发送事假给 除了自己之外的其他页面
      })
})
app.use(views(__dirname+"/views"));
app.use(static(__dirname+"/static"));
router.get("/index",async ctx=>{
   await ctx.render("index.html");
});

app.use(router.routes());
server.listen(8989);

// 作业：1.复习 2.拖拽方块 --->2个页面的方块拖拽同步